package com.example.demo.service;


import com.example.demo.dao.UserManagerDAO;
import com.example.demo.po.UserManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserManagerService {

    @Autowired
    UserManagerDAO userDao;

    public UserManage getByUserName(String userName){
        return userDao.getByUserName(userName);
    }

    public boolean saveOrUpdate(UserManage userManage){
        String pwd =userManage.getUserPwd();
        String md5 =DigestUtils.md5DigestAsHex(pwd.getBytes());
        userManage.setUserPwd(md5);
        if(userManage.getId()!=null) {
            int i = userDao.update(userManage);
            if(i!=1)
                return  false;
            else
                return  true;
        }else{
            userDao.save(userManage);
            if(userManage.getId()!=null)
                return  true;
            else
                return  false;
        }
    }
}
